var a = getApp();

Page({
    data: {
        language: "",
        name: "",
        page: 0
    },
    onLoad: function(a) {
        this.setData({
            name: a.name
        }), this.getData();
    },
    gosearch: function(a) {
        this.getData();
    },
    search: function(a) {
        console.log(a), this.setData({
            name: a.detail.value
        });
    },
    getData: function() {
        var t = wx.getStorageSync("address-point"), e = t.point.lat, n = t.point.lng, d = t.city, s = this, o = a.getNetAddresss("plugin.easy-refuel.frontend.index.searchByName"), i = {
            lng: n,
            lat: e,
            name: s.data.name,
            cityName: d,
            page: s.data.page
        };
        a._postNetWork({
            url: o,
            data: i,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    for (var e = 0; e < t.data.data.data.length; e++) {
                        t.data.data.data[e].distance = t.data.data.data[e].distance.toFixed(2) + "km";
                        for (var n = 0; n < t.data.data.data[e].prices.length; n++) t.data.data.data[e].prices[n].muns = (Number(t.data.data.data[e].prices[n].discountPrice) - Number(t.data.data.data[e].prices[n].countryPrice)).toFixed(2);
                    }
                    s.setData({
                        banner: t.data.banner,
                        datas: t.data.data.data,
                        shopName: t.data.shopName,
                        last_page: t.data.data.last_page,
                        current_page: t.data.data.current_page
                    }), wx.setNavigationBarTitle({
                        title: t.data.shopName
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getNextData: function() {
        var t = wx.getStorageSync("address-point"), e = t.point.lat, n = t.point.lng, d = t.city, s = this, o = a.getNetAddresss("plugin.easy-refuel.frontend.index.searchByName"), i = {
            lng: n,
            lat: e,
            name: s.data.name,
            cityName: d,
            page: s.data.page
        };
        a._postNetWork({
            url: o,
            data: i,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    for (var e = 0; e < t.data.data.data.length; e++) {
                        t.data.data.data[e].distance = t.data.data.data[e].distance.toFixed(2) + "km";
                        for (var n = 0; n < t.data.data.data[e].prices.length; n++) t.data.data.data[e].prices[n].muns = (Number(t.data.data.data[e].prices[n].discountPrice) - Number(t.data.data.data[e].prices[n].countryPrice)).toFixed(2);
                    }
                    s.setData({
                        banner: t.data.banner,
                        datas: s.data.datas.concat(t.data.data.data),
                        shopName: t.data.shopName,
                        last_page: t.data.data.last_page,
                        current_page: t.data.data.current_page
                    }), wx.setNavigationBarTitle({
                        title: t.data.shopName
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.current_page >= this.data.last_page ? wx.showToast({
            title: "暂无更多",
            duration: 1e3,
            icon: "none"
        }) : (this.setData({
            page: this.data.page + 1
        }), this.getNextData());
    },
    onShareAppMessage: function() {}
});